package org.hackystat.sdsa.analyzer.control.processor;

import java.util.Map;
import java.util.logging.Logger;

import org.hackystat.sdsa.analyzer.control.SensorDataUtil;
import org.hackystat.sdsa.analyzer.model.activity.Activity;
import org.hackystat.sdsa.analyzer.model.activity.CompilationActivity;
import org.hackystat.sensorbase.resource.sensordata.jaxb.SensorData;

/**
 * Provides a processor to process compilation activity.
 * 
 * @author hongbing
 *
 */
public class CompilationActivityProcessor implements Processor {

  /**
   * Process the given sensor data to construct a compilation activity.
   * 
   * @param sensorData Sensor data.
   * @param logger Logger.
   * @return Compilation activity.
   */
  public Activity process(SensorData sensorData, Logger logger) {
    return new CompilationActivity(sensorData, logger);
  }

  /**
   * Checks whether this sensor is a compilation activity or not.
   * 
   * @param sensorData Sensor data.
   * @return True if this is a compilation activity.
   */
  public boolean processable(SensorData sensorData) {
    String sensorDataType = sensorData.getSensorDataType();
    Map<String, String> propMap = SensorDataUtil.propMap(sensorData);
    
    if (!"DevEvent".equalsIgnoreCase(sensorDataType)) {
      return false;
    }
    
    if (!propMap.containsKey("type") || !"Build".equalsIgnoreCase(propMap.get("type"))) {
      return false;
    }
    
    return true;  
  }
}
